<!doctype html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Java 参数传递机制深度解析</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
        }
        .serif-font {
            font-family: 'Noto Serif SC', serif;
        }
        .gradient-text {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .code-block {
            background: #1e1e1e;
            border-radius: 12px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
            transition: transform 0.3s ease;
        }
        .code-block:hover {
            transform: translateY(-2px);
            box-shadow: 0 15px 40px rgba(0, 0, 0, 0.3);
        }
        .concept-card {
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            transition: all 0.3s ease;
        }
        .concept-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
        }
        .drop-cap {
            float: left;
            font-size: 4rem;
            line-height: 1;
            font-weight: 700;
            margin-right: 0.5rem;
            margin-top: 0.2rem;
            color: #667eea;
        }
        pre code {
            color: #d4d4d4;
            font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
        }
        .keyword { color: #569cd6; }
        .string { color: #ce9178; }
        .method { color: #dcdcaa; }
        .class { color: #4ec9b0; }
        .number { color: #b5cea8; }
        .comment { color: #6a9955; }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 px-6">
        <div class="max-w-6xl mx-auto">
            <div class="text-center">
                <h1 class="text-5xl md:text-6xl font-bold mb-6 serif-font">
                    Java 参数传递机制
                </h1>
                <p class="text-xl md:text-2xl mb-8 opacity-90">
                    深入理解值传递与引用传递的本质区别
                </p>
                <div class="flex justify-center space-x-4">
                    <span class="bg-white bg-opacity-20 px-4 py-2 rounded-full text-sm">
                        <i class="fas fa-code mr-2"></i>核心概念
                    </span>
                    <span class="bg-white bg-opacity-20 px-4 py-2 rounded-full text-sm">
                        <i class="fas fa-memory mr-2"></i>内存分析
                    </span>
                    <span class="bg-white bg-opacity-20 px-4 py-2 rounded-full text-sm">
                        <i class="fas fa-lightbulb mr-2"></i>实例解析
                    </span>
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="max-w-6xl mx-auto px-6 py-16">
        <!-- Introduction -->
        <section class="mb-16">
            <div class="bg-white rounded-2xl shadow-lg p-8 md:p-12">
                <h2 class="text-3xl font-bold mb-6 gradient-text">引言</h2>
                <p class="text-lg leading-relaxed text-gray-700">
                    <span class="drop-cap serif-font">在</span>Java编程中，参数传递机制是一个经常引起困惑的话题。许多开发者对于"Java到底是值传递还是引用传递"这个问题存在误解。本文将通过具体的代码示例和内存分析，深入剖析Java的参数传递机制，帮助你彻底理解这个核心概念。
                </p>
            </div>
        </section>

        <!-- Code Example 1 -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-8 text-center">
                <i class="fas fa-code-branch mr-3 text-purple-600"></i>
                示例一：String 参数传递
            </h2>
            
            <div class="grid md:grid-cols-2 gap-8">
                <div class="code-block p-6">
                    <div class="flex items-center mb-4">
                        <i class="fas fa-terminal mr-2 text-green-400"></i>
                        <span class="text-gray-400 text-sm">StringExample.java</span>
                    </div>
                    <pre><code><span class="keyword">public static void</span> <span class="method">main</span>(<span class="class">String</span>[] args) {
    <span class="class">String</span> str = <span class="keyword">new</span> <span class="class">String</span>(<span class="string">"zhangsan"</span>);
    <span class="method">change</span>(str);
    <span class="class">System</span>.out.<span class="method">println</span>(str);
}

<span class="keyword">public static void</span> <span class="method">change</span>(<span class="class">String</span> str1) {
    str1 = <span class="string">"xiaowang"</span>;
}</code></pre>
                </div>
                
                <div class="bg-white rounded-xl shadow-lg p-6">
                    <h3 class="text-xl font-bold mb-4">
                        <i class="fas fa-terminal mr-2 text-green-600"></i>
                        输出结果
                    </h3>
                    <div class="bg-gray-900 text-green-400 p-4 rounded-lg font-mono">
                        zhangsan
                    </div>
                    <div class="mt-6">
                        <h4 class="font-bold text-lg mb-2 text-gray-700">
                            <i class="fas fa-question-circle mr-2 text-blue-600"></i>
                            为什么输出是 zhangsan？
                        </h4>
                        <p class="text-gray-600 leading-relaxed">
                            这个结果揭示了Java参数传递的核心机制。让我们通过内存分析来理解这个过程。
                        </p>
                    </div>
                </div>
            </div>
        </section>

        <!-- Memory Analysis -->
        <section class="mb-16">
            <div class="bg-gradient-to-r from-purple-50 to-blue-50 rounded-2xl p-8 md:p-12">
                <h2 class="text-3xl font-bold mb-8 text-center">
                    <i class="fas fa-memory mr-3 text-purple-600"></i>
                    内存分析图解
                </h2>
                
                <div class="bg-white rounded-xl shadow-lg p-8">
                    <img src="https://cdn.nlark.com/yuque/0/2022/png/21449790/1665994829129-5411bbbd-9b44-4cc1-a1c7-a7648f05ecc0.png" 
                         alt="Java参数传递内存分析" 
                         class="w-full rounded-lg shadow-md">
                    
                    <div class="mt-8 grid md:grid-cols-3 gap-6">
                        <div class="concept-card rounded-lg p-6">
                            <i class="fas fa-layer-group text-3xl text-purple-600 mb-3"></i>
                            <h4 class="font-bold text-lg mb-2">栈内存</h4>
                            <p class="text-gray-600 text-sm">存储方法的局部变量和参数引用</p>
                        </div>
                        <div class="concept-card rounded-lg p-6">
                            <i class="fas fa-database text-3xl text-blue-600 mb-3"></i>
                            <h4 class="font-bold text-lg mb-2">堆内存</h4>
                            <p class="text-gray-600 text-sm">存储对象实例和字符串常量</p>
                        </div>
                        <div class="concept-card rounded-lg p-6">
                            <i class="fas fa-exchange-alt text-3xl text-green-600 mb-3"></i>
                            <h4 class="font-bold text-lg mb-2">值传递</h4>
                            <p class="text-gray-600 text-sm">传递的是引用的副本，而非引用本身</p>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Code Example 2 -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-8 text-center">
                <i class="fas fa-user-cog mr-3 text-blue-600"></i>
                示例二：对象参数传递
            </h2>
            
            <div class="grid md:grid-cols-2 gap-8">
                <div class="code-block p-6">
                    <div class="flex items-center mb-4">
                        <i class="fas fa-terminal mr-2 text-green-400"></i>
                        <span class="text-gray-400 text-sm">UserExample.java</span>
                    </div>
                    <pre><code><span class="keyword">public static void</span> <span class="method">main</span>(<span class="class">String</span>[] args) {
    <span class="class">User</span> user = <span class="keyword">new</span> <span class="class">User</span>();
    user.<span class="method">setId</span>(<span class="number">10</span>);
    <span class="method">change</span>(user);
    <span class="class">System</span>.out.<span class="method">println</span>(user.<span class="method">getId</span>());
}

<span class="keyword">public static void</span> <span class="method">change</span>(<span class="class">User</span> user1) {
    user1.<span class="method">setId</span>(<span class="number">100</span>);
}</code></pre>
                </div>
                
                <div class="bg-white rounded-xl shadow-lg p-6">
                    <h3 class="text-xl font-bold mb-4">
                        <i class="fas fa-terminal mr-2 text-green-600"></i>
                        输出结果
                    </h3>
                    <div class="bg-gray-900 text-green-400 p-4 rounded-lg font-mono">
                        100
                    </div>
                    <div class="mt-6">
                        <h4 class="font-bold text-lg mb-2 text-gray-700">
                            <i class="fas fa-lightbulb mr-2 text-yellow-500"></i>
                            关键差异
                        </h4>
                        <p class="text-gray-600 leading-relaxed">
                            与String示例不同，这里修改的是对象的属性，而不是重新赋值引用。两个引用指向同一个对象，因此修改会生效。
                        </p>
                    </div>
                </div>
            </div>
        </section>

        <!-- Concept Visualization -->
        <section class="mb-16">
            <div class="bg-white rounded-2xl shadow-lg p-8 md:p-12">
                <h2 class="text-3xl font-bold mb-8 text-center gradient-text">
                    核心概念关系图
                </h2>
                
                <div class="mermaid text-center">
                    graph TD
                    A[Java参数传递] --> B[值传递]
                    B --> C[基本类型]
                    B --> D[引用类型]
                    C --> E[传递值的副本]
                    D --> F[传递引用的副本]
                    F --> G[String不可变性]
                    F --> H[对象可变性]
                    G --> I[重新赋值无效]
                    H --> J[修改属性有效]
                    
                    style A fill:#667eea,stroke:#fff,stroke-width:3px,color:#fff
                    style B fill:#764ba2,stroke:#fff,stroke-width:2px,color:#fff
                    style C fill:#f093fb,stroke:#fff,stroke-width:2px,color:#fff
                    style D fill:#f093fb,stroke:#fff,stroke-width:2px,color:#fff
                </div>
            </div>
        </section>

        <!-- Key Takeaways -->
        <section class="mb-16">
            <div class="bg-gradient-to-r from-yellow-50 to-orange-50 rounded-2xl p-8 md:p-12">
                <h2 class="text-3xl font-bold mb-8 text-center">
                    <i class="fas fa-key mr-3 text-orange-600"></i>
                    核心要点总结
                </h2>
                
                <div class="grid md:grid-cols-2 gap-6">
                    <div class="bg-white rounded-xl shadow-md p-6 hover:shadow-xl transition-shadow">
                        <div class="flex items-start">
                            <span class="text-3xl font-bold text-purple-600 mr-4">1</span>
                            <div>
                                <h3 class="